package com.cqrt.mapper;


import com.alibaba.fastjson.JSONObject;
import com.cqrt.dto.OAProjectJobDTO;
import com.cqrt.entity.RTPrjTaskJobLinkDO;
import com.cqrt.vo.MIBAVO;
import com.cqrt.vo.OAPlanVO;
import com.cqrt.vo.SubJobVO;
import com.cqrt.vo.TyJobVO;
import com.hustcad.plm.pdm.common.model.dto.search.SearchTypeDTO;
import com.hustcad.plm.rpm.model.dto.job.TyppmJobDTO;
import com.ty.basic.entity.local.LocalePropertyValueDO;
import com.ty.ppm.model.entity.job.Job;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

@Mapper
public interface RTTaskMapper {

    //通过任务ID查询活动ID
    BigInteger selectActivityIdById(String Oid);

    //查询出前置任务的OID
    List<BigInteger> selectBOidByAOid(String BOid);

    //通过活动ID查询任务状态
    String selectStateByActivityId(String ActivityId);

    @Select("select PARENTNODEOID from TY_PJ_JOB where OID=TO_NUMBER(#{jobId})")
    BigInteger selectParentById(String jobId);


    BigInteger selectParentByJobId(String jobId);

    @Select("select PRJID from TY_PJ_JOB where OID=TO_NUMBER(#{jobId})")
    BigInteger selectPrjByID(String jobId);

    @Select("select * from TY_PJ_JOB where PARENTNODEOID=#{parentID}")
    List<Job> selectAllJobByParentID(BigInteger parentID);

    List<Job> selectJobByUserId(String userId,String prjId,String jobName);

    void updateParentTask(BigInteger parentID);

    @Select("select * from TY_LOCALEPROPERTYVALUE where VALUE=#{deliverableType} AND HOLDREFERENCEOID=15325")
    LocalePropertyValueDO selectRuleTypeByName(String deliverableType);

    SearchTypeDTO selectTypeByName(String value);

    void insertTaskLink(RTPrjTaskJobLinkDO rtPrjTaskJobLinkDO);

    @Select("select * from RT_PRJ_TASK_JOB_LINK where TASKOID=TO_NUMBER(#{oid}) AND STATUS='0'")
    RTPrjTaskJobLinkDO existTemporaryTask(String jobId);

    Integer countIssubmit(BigInteger taskoid);

    @Update("update RT_PRJ_TASK_JOB_LINK set STATUS = '1' where TASKOID=#{taskoid}")
    void updateTaskState(BigInteger taskoid);

    String selectProjectTypeNameByOid(@Param("oid") String projectOid);

    List<Job> selectJobByName(@Param("jobList") Set<String> jobList, @Param("oid") BigInteger oid);

    List<SubJobVO> selectSubJobsByPrjId(@Param("oid")BigInteger oid,@Param("name")String name);

    @Select("select  COUNT(*) from RT_PRJ_TASK_JOB_LINK where JOBOID = TO_NUMBER(#{jobId})")
    int queryTempoaryCount(String jobId);

    @Select("select count(*) from RT_PRJ_TASK_JOB_LINK where joboid= #{jobId} and status='0' ")
    int queryTemporaryTaskIds(String jobId);

    List<String> queryTheIdOfTheTemporaryTaskThatNeedsToBePaused();

    void updateProjectJobExecutionStatus(@Param("ids") List<String> ids);

    void setProjectExecutionStatus(@Param("objId") String pjId);

    void setProjectJobExecutionStatus(@Param("objId")String pjId);

    String getProjectIdByName(@Param("name")String projectName);

    List<TyJobVO> obtainTheProjectTaskId(@Param("pjId") String pjOid);

    void updateProjectJobTime(OAProjectJobDTO p);

    String setIsState(@Param("prj") String projectoid, @Param("projectphase")String projectphase);

    void deleteOutRule(@Param("oid") String oid);

    void deleteJobDeleverLink(@Param("oid")String oid);

    void updateJobState(@Param("jobDTOList") List<TyppmJobDTO> jobDTOList);

    void changeJobSubmitState(String jobId);

    List<RTPrjTaskJobLinkDO> selectJobById(BigInteger oid);

    void deleteJobDeleverLinkByabID(@Param("aoid") String aoid,@Param("boid") String boid);

    /**
     * 更新项目计划执行状态为完成
     *
     * @return
     */
    int updateProjectPlanExecutionStatusToCompleted(@Param("jobId") String jobId, @Param("status") String status);

    /**
     * 查询任务执行状态
     */
    @Select("select value from TY_STRINGVALUE " +
            "where ATTRDEFOID=(select oid from TY_STRINGDEF where name ='ExecutionStatus') " +
            "and OBJBASEOTYPE='ty.projectmng.job.CTyJob' " +
            "and OBJBASEOID=TO_NUMBER(#{jobId})"+
            "AND ROWNUM = 1")
    String selectJobExecutionStatus(@Param("jobId") String jobId);

    String selectOBJIdInDeliverlink(String linkOid);

    String selectStateByJobOId(BigInteger jobOId);

    List<String> selectStandardName();

    List<MIBAVO> selectIBAById(@Param("id") String oid);

    List<OAPlanVO> selectPlanByProjectId(@Param("id") String projectId);

    /**
     * 查询齐套性点检表的OID
     * @return 齐套性点检表的OID
     */
    @Select("SELECT OID FROM (select OID from TY_DOC\n" +
            "                       where masteredoid = #{oid} " +
            "and ISLASTITERATED =1" +
            "order by CREATESTAMP desc\n" +
            "\t\t\t\t\t\t\t\t\t\t\t )\n" +
            "\t\t\t\t\t\t\t\t\t\t\t \n" +
            "\t\t\t\t\t\t\t\t\t\t\t WHERE ROWNUM=1")
    List<BigInteger> selectCheckDocOid(String oid);

    String selectExecutedStatus(String jobId);

    BigInteger selectExecutionStatus(String executionStatus);

    void updateExecutionStatus(String executionStatus, BigInteger projectOid, BigInteger executionStatusId);

    String selectRootPlanIdByPlanId(String id);

    String selectPlanIdByProjectId(String projectId);

    List<BigInteger> selectJobIdByProjectId(BigInteger projectId);

    String selectPlanId(String planId);

    List<String> selectInspectionChecklistDoc();

    List<JSONObject> queryParentJobOid(@Param("list") List<String> list);

    List<JSONObject> queryJobNameByJobOid(@Param("list") List<String> jobOids);

    String selectActivityByName(@Param("name") String name,@Param("outLineNumber") String outLineNumber,@Param("outLineLevel") String outLineLevel,@Param("planId") String planId);

    String selectExtPropByJobOid(String jobOid);

    BigInteger selectTaskIsExist(@Param("oid")BigInteger oid,@Param("name")String name);
    List<BigInteger> selectKnowledgeLinkDoc(String jobOid);

    LocalDateTime selectStartTime(String jobOid);

    void updateJobRiskTypeByOid(@Param("jobOid") String jobOid, @Param("risk") String risk);

    void updateActualFinshTime(String jobOid);

    LocalDateTime selectActualFinshTime(String jobOid);

    List<TyppmJobDTO> queryWaitingProjectTasks(BigInteger oid);

    List<String> selectTemporaryJobOid(@Param("jobId") String jobId);

    String selectJobRiskByOid(String jobOid);

    LocalDateTime selectActualStartTime(String jobOid);

    void updateActualStartTime(String jobOid);

    void updateExcutorByJobId(String jobId, String newExecutorId);

    List<Job> queryExecutorJobByCurrentUser(List<String> stateList, BigInteger excutorOid,BigInteger priattr);

    void updateExecutorByActivityId(BigInteger oid, String newExecutorId);

    void updateWorkByActivityId(BigInteger oid, String tags);

}
